﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SharpShare.Utilities.NodeTracking {
    public class NumberTokenGenerator : ITokenGenerator<int>, ITokenGenerator<short>, ITokenGenerator<ushort>, ITokenGenerator<uint>, ITokenGenerator<long> {
        private long _current;

        public NumberTokenGenerator(long seed = 0) {
            _current = seed;
        }

        public long Next() {
            return Interlocked.Increment(ref _current);
        }

        #region ITokenGenerator<int> Members

        int ITokenGenerator<int>.Next() {
            unchecked {
                return (int)this.Next();
            }
        }

        IEqualityComparer<int> ITokenGenerator<int>.Comparer {
            get { return null; }
        }

        #endregion

        #region ITokenGenerator<long> Members

        IEqualityComparer<long> ITokenGenerator<long>.Comparer {
            get { return null; }
        }

        #endregion

        #region ITokenGenerator<short> Members

        short ITokenGenerator<short>.Next() {
            unchecked {
                return (short)Next();
            }
        }

        IEqualityComparer<short> ITokenGenerator<short>.Comparer {
            get { return null; }
        }

        #endregion

        #region ITokenGenerator<uint> Members

        uint ITokenGenerator<uint>.Next() {
            unchecked {
                return (uint)Next();
            }
        }

        IEqualityComparer<uint> ITokenGenerator<uint>.Comparer {
            get { return null; }
        }

        #endregion

        #region ITokenGenerator<ushort> Members

        ushort ITokenGenerator<ushort>.Next() {
            unchecked {
                return (ushort)Next();
            }
        }

        IEqualityComparer<ushort> ITokenGenerator<ushort>.Comparer {
            get { return null; }
        }

        #endregion
    }

}
